const flv = window.flvjs
var u = navigator.userAgent, app = navigator.appVersion, ua = navigator.userAgent.toLowerCase()
export	const isMobile = (function(){
  let flag = u.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
  return flag
})()
export	let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);               //ios终端
export	let isWeixin = ua.match(/MicroMessenger/i) == "micromessenger";       //是否微信  
export	let isqq = u.match(/\sQQ/i) == " QQ";
export	let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
export  let isHuwei = navigator.userAgent.toLowerCase().indexOf('huawei') > -1 || navigator.userAgent.toLowerCase().indexOf('honor') > -1
export function createNode(htmlStr) {
	var div = document.createElement("div");
	div.innerHTML = htmlStr;
	return div.childNodes[0];
}
export function	stringLen(str){
	return str.replace(/[^\x00-\xff]/g, 'xx').length;
}
export let flvCommon = (function(){
	let flvSupport = (function(){
		let flvSuppot
		// if(isHuwei && (!isqq || !isWeixin)){
		// 	flvSuppot = false
		// }else{
		flvSuppot = flv.getFeatureList().mseLiveFlvPlayback && !isIOS
		// }
		return flvSuppot;
	})()
	let pcflvSupport = (function(){
		let flvSuppot
		flvSuppot = flv.getFeatureList().mseLiveFlvPlayback && !isIOS
		return flvSuppot;
	})()
	let createFlvPlayer = function(url,videoElement){
    let flvPlayer = flv.createPlayer({
      type: 'flv',
      url: url
	},{
        enableWorker: true,
        enableStashBuffer: false,
        stashInitialSize: 128,
		});
    flvPlayer.attachMediaElement(videoElement);
    return flvPlayer;
	}
	let destroyFlvPlayer = function(flvPlayer,flvPlayerPlaying){
		flvPlayer.pause();
    flvPlayer.unload();
		flvPlayer.detachMediaElement();
		flvPlayer.destroy();
	}
	return{
		flvSupport:flvSupport,
		pcflvSupport:pcflvSupport,
		createFlvPlayer:createFlvPlayer,
		destroyFlvPlayer:destroyFlvPlayer,
	}
})()
export function toggleClass(element, className) {
  if (!element || !className) {
    return
  }
  let classString = element.className
  const nameIndex = classString.indexOf(className)
  if (nameIndex === -1) {
    classString += '' + className
  } else {
    classString =
      classString.substr(0, nameIndex) +
      classString.substr(nameIndex + className.length)
  }
  element.className = classString
}
export function hasClass(ele, cls) {
  return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
}

/**
 * Add class to element
 * @param {HTMLElement} elm
 * @param {string} cls
 */
export function addClass(ele, cls) {
  if (!hasClass(ele, cls)) ele.className += ' ' + cls
}

/**
 * Remove class from element
 * @param {HTMLElement} elm
 * @param {string} cls
 */
export function removeClass(ele, cls) {
  if (hasClass(ele, cls)) {
    const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
    ele.className = ele.className.replace(reg, ' ')
  }
}
export function arrayInsert(arr,index, item){
	arr.splice(index, 0, item)
}
export function arrayRemove(arr,from, to){
	var rest = arr.slice((to || from) + 1 || arr.length);
	arr.length = from < 0 ? arr.length + from : from;
	arr.push.apply(arr, rest);
}